import { system } from "./base";

export async function availablePorts() {
    return (await system.get('/available_ports')).parse<string[]>();
}

export async function macAddress() {
    return (await system.get('/mac_address')).parse<string>();
}

export async function openSerialPort(name: string, baudRate: number) {
    const arg = {
        name,
        baud_rate: baudRate
    };
    await system.post('/open_port', arg);
}

export async function closeSerialPort() {
    await system.post('/close_port');
}

export async function serialPortIsOpen() {
    return (await system.get('/port_is_open')).parse<boolean>();
}

export async function serialPortWrite(buf: Uint8Array) {
    const arg = {
        data: buf,
    };
    await system.post('/write_port', arg);
}

export async function ping(dst: number) {
    await system.post('/ping', dst);
}
